﻿$(function(){//延迟加载  
	var ipresId='';
	var swip='';
	var swname='';
	$('#brasname').validatebox({
		required:true
	});

	$('#advlan').numberbox({
		required:true
	});
	$('#braslevel').combobox();
	
	$('#xhrow').load('dvfirmsec',function(){
		$.getScript('/xasj/js/component/dvmodelsec.js');
	});
	
	$('#jfrow').load('showjifangsec',function(){
		$.getScript('/xasj/js/component/jifangsec.js');
	});
	
	
	$('#requestipnum').numberbox({
		prompt:'请求数量',
		value:4,
		min:3,
		//max:20,
		required:true
	});
	
	$('#getbrasip').textbox({//获取IP
		buttonText:'获取IP',
		buttonIcon:'icon-redo',
		prompt:'自动获取...',
		onClickButton:function(){
			if($('#jifang').combobox('getValue')=='请选择'||$('#jifang').combobox('getValue')==''||$('#requestipnum').val()==''){
				alert('请选择机房和需求的IP数')
			}else{
				//alert($('#jifang').combobox('getValue')+$('#requestipnum').val());
				var url='requestip?jfId='+$('#jifang').combobox('getValue')
				+'&requestipnum='+$('#requestipnum').val()+'&dvbelong=switchip'+'&djxId='
				+$('#dajuxiang').combobox('getValue');
				//alert(url);
				$.ajax({					
					url:'requestip?jfId='+$('#jifang').combobox('getValue')
					+'&requestipnum='+$('#requestipnum').val()+'&dvbelong=brasip'+'&djxId='
					+$('#dajuxiang').combobox('getValue'),
					type:'get',
					dataType:'json',
					success:function(data){
						//alert(data.iprange);
						if(data.msg!='1'){
							alert(data.msg);
							return
						}
						ipdeployId=data.ipdeployId;
						ipresId=data.ipresId;
						$('#getbrasip').textbox('setValue',data.dvip);
						$('#getgw').textbox('setValue',data.dvgateway);
						$('#iprange').textbox('setValue',data.iprange);
						alert(ipresId);
					}
				})
			}
		}
	});

	$('#comaddbras').click(function(){
		if(!$('#st1').form('validate')){
			alert('信息不完整!');
    		return;
    	}
		brasip=$('#getbrasip').val();
		brasname=$('#brasname').val();
		var jfId=$('#jifang').combobox('getValue');
		var dvmodelId=$('#dvmodel').combobox('getValue');
		var iprange=$('#iprange').val();
		var gateway=$('#getgw').val();
		$.ajax({
			url:'addnewbras',
			type:'POST',
			data:{
				brasip:brasip,
				brasname:brasname,
				jfId:jfId,
				dvmodelId:dvmodelId,
				iprange:iprange,
				gateway:gateway
			},
			success:function(data){
				alert(data.msg);
			}
		});
	});
	
    $.extend($.fn.validatebox.defaults.rules, {    
    	 ip : {// 验证IP地址  
             validator : function(value) {  
                 var reg = /^((1?\d?\d|(2([0-4]\d|5[0-5])))\.){3}(1?\d?\d|(2([0-4]\d|5[0-5])))$/ ;  
                 return reg.test(value);  
             	},  
             message : 'IP地址格式不正确'  
    	 	}
    });
});